<template>
	<view class="community">
		<view class="head_bg">
		</view>
		<view class="big_box" style="height: auto;">
			<view class="big_box_inner">
				<view class="big_inner_one">
					<view class="ele_title">
						<view class="ele_title_left">
							<view class="ele_title_inner">
							<!-- <image class="ele_address_img" src="../../../common/img/gongsi_hui.png" mode=""></image> -->
							{{obj.residential_quarters_name}}</view>
							<view class="ele_address">
								<image class="ele_address_img" src="../../../common/img/dizhi_hui.png" mode=""></image>
								<text>{{obj.residential_quarters_address}}</text>
							</view>
						</view>
						<view class="ele_add" @tap="toadd">+新增</view>
					</view>
					<view class="ele_list" v-for="(info,index) in list" :key="index">
						<view class="ele_list_left">
							<view class="ele_list_p">项目名称:{{info.name_of_expenditure}}</view>
							<view class="ele_list_p">成本:{{info.expenditure_amount}}元</view>
							<view class="ele_list_p">备注:{{info.remark}}</view>
						</view>
						<view class="ele_list_right">
							<image @tap="delcost(info._id)" class="ele_list_img" src="../../../common/img/delxq.png" style="width:99rpx;height:85rpx;" mode=""></image>
							<view class="ele_list_p">时间:{{info.spending_time}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-if="list.length==0" class="margin-top-lg text-center">
			<image src='../../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
		</view>
		<view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
			{{loadingTxt}} 共({{totle}}条记录)
		</view>
	</view>
</template>

<script>
	let page=1,timer=null
	export default {
		data() {
			return {
				obj:[],
				list:[],
				total:0,
				loadingTxt:'加载更多',
				info:{
					_id:0,//	整型	主键ID
					name_of_expenditure:'',//	字符串	支出名称
					spending_time:'',//	字符串	支出时间
					expenditure_amount:0.00,//	浮点型	支出金额
					remark:'',//	字符串	备注

				},
				guid:''
			}
		},
		onLoad(options) {
			this.obj=JSON.parse(options.item);
		},
		onShow() {
			page=1;
			this.getList();
		},
		methods: {
			toadd(){
				uni.navigateTo({
					url: '../addCost/addCost??item='+JSON.stringify(this.obj)
				})
			},
			getList(){
				let that=this;
				that.http.tokenreq({
					url: 'costcontrol/v1/list',
					data: {
				    "pageindex":page,
					'residential_quarters_guid':this.obj.residential_quarters_guid
					}
				}).then((res) => {
					let e=res.data;
					console.log(e);
					if(e.code==0 && e.success){
						this.list = e.rows;
						this.totle= e.total;
						page++;
					}
				})
			},
			getmorelist(){
				this.loadingTxt='加载中'
				let that=this;
				that.http.tokenreq({
					url: 'costcontrol/v1/list',
					data: {
				    "pageindex":page,
					'residential_quarters_guid':this.obj.residential_quarters_guid
					}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						if(e.rows.length==0){
							that.loadingTxt="已经加载全部";
							return;
						}
						that.list=that.list.concat(e.rows);
						page++;
					}
				})
			},
			onReachBottom() {
				//阻止重复加载
				if(timer !== null){
					clearTimeout(timer)
				}
				timer=setTimeout(()=>this.getmorelist(),500)
				// this.getMoreNews()
			},
			//删除成本
			delcost(number){
				let that=this;
				uni.showModal({
					title: '提示',
					content: '确定要删除该小区成本信息吗?',
					success: function (res) {
						if (res.confirm) {
							that.suredel(number);
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			suredel(number){
				let that=this;
				uni.showLoading();
				that.http.tokenreq({
					url: 'costcontrol/v1/del',
					data:{"id":number}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						uni.hideLoading();
						uni.showModal({
							content: e.message,
							showCancel:false,
							success: function (res) {
								if (res.confirm) {
									page=1;
									that.getList();
								}
							}
						});
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			}
		}
	}
</script>
<style>
	.big_box{
	    margin-top:-100rpx;
	}
</style>
